// https://vitejs.dev/config/
import { ConfigEnv, defineConfig, loadEnv } from 'vite'
import pkg from './package.json'
import { dayjs } from 'element-plus'
import { resolve } from 'path'
import { setupVitePlugins } from './build'

const { dependencies, devDependencies, name, version } = pkg
const __APP_INFO__ = {
  pkg: { dependencies, devDependencies, name, version },
  lastBuildTime: dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
}
export default defineConfig((configEnv: ConfigEnv) => {
  const viteEnv = loadEnv(configEnv.mode, process.cwd()) as ImportMetaEnv // 加载 VITE_前缀的环境变量
  return {
    base: viteEnv.VITE_BASE_URL,
    build: undefined,
    plugins: setupVitePlugins(viteEnv),
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
      }
    },
    server: {
      host: '0.0.0.0',
      port: 8848,
      open: true,
      https: false,
      // 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
      proxy: {}
    },
    define: { __APP_INFO__: JSON.stringify(__APP_INFO__) }
  }
})
